package com.example.lzy.listviewsample.com.example.lzy.listviewsample.zdy;

import android.app.Activity;
import android.support.annotation.NonNull;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import com.example.lzy.listviewsample.R;

/**
 * Created by lzy on 2018/4/9.
 */

public class MyArrayAdapter extends ArrayAdapter {
    private Activity mContext = null;
    private int mResourceId;
    private String[] mItems;

    public MyArrayAdapter(Activity context, int resId,String[] items) {
        super(context, resId,items);

        mContext = context;
        mResourceId = resId;
        mItems = items;
    }

    @NonNull
    @Override
    public View getView(int position , View convertView, ViewGroup parent){

        LayoutInflater inflater = mContext.getLayoutInflater();
        View itemView = inflater.inflate(mResourceId,null);
        TextView contentTv = (TextView) itemView.findViewById(R.id.text);
        ImageView imageView = (ImageView) itemView.findViewById(R.id.img);

        String content = mItems[position].trim();

        contentTv.setText(content);

        if(content.startsWith("a")){
            imageView.setImageResource(R.drawable.two_icon);
        }else {
            imageView.setImageResource(R.mipmap.ic_launcher);
        }

        return  itemView;

    }

}

